package com.lysj.admin.log.feign;

import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.bean.copier.CopyOptions;
import com.lysj.admin.common.log.domain.SuperLog;
import com.lysj.admin.common.log.feign.LogServiceFeign;
import com.lysj.admin.log.domain.Log;
import com.lysj.admin.log.service.LogService;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * @author Created by zk on 2019-01-17 11:03
 * @description
 */
@RestController
public class LogServiceFeignImpl implements LogServiceFeign {
    @Resource
    private LogService logService;
    @Override
    public void saveLog(@RequestBody SuperLog superLog) {
        try {
            CopyOptions copyOptions = new CopyOptions();
            copyOptions.setIgnoreNullValue(true);
            Log log = new Log();
            BeanUtil.copyProperties(superLog,log,copyOptions);
            logService.save(log);
        }catch (Exception e){
            Log log = new Log();
            log.setRequestParam(e.getStackTrace()[0]+"--"+e.toString());
            logService.save(log);
        }
    }
}
